package net.ithe.controller;

import lombok.extern.slf4j.Slf4j;
import net.ithe.pojo.Emp;
import net.ithe.pojo.LoginInfo;
import net.ithe.pojo.Result;
import net.ithe.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录Controller
 */
@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpService empService;
    /**
     * 登录
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("登录,参数:{}",emp);
        LoginInfo loginInfo=empService.login(emp);
        if (loginInfo!=null){
            return Result.success(loginInfo);
        }else {
            return Result.error("用户名或密码错误");
        }
    }
    /**
     * 注册
     * @return
     */
    @PostMapping("/register")
    public Result register(@RequestBody Emp emp){
        log.info("注册,参数:{}",emp);
        empService.save(emp);
        return Result.success();
    }
}
